package com.sgb.trip.view.adapter;

import android.content.Context;

import androidx.databinding.DataBindingUtil;

import com.sgb.trip.R;
import com.sgb.trip.databinding.TripItemDetailInsureBinding;
import com.sgb.trip.entity.FlightOrderDetailEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.NumberUtil;

import java.util.List;

/**
 * Time:2021/6/18
 * Author:黄淋
 * Description:选择保险时的adapter
 */
public class InsureServiceDetailAdapter extends BaseRecycleAdapter<FlightOrderDetailEntity.OrderPriceDetailsBean.InsurancePricesBean> {
    boolean isBack;
    int passengerCount;

    public InsureServiceDetailAdapter(Context context, List<FlightOrderDetailEntity.OrderPriceDetailsBean.InsurancePricesBean> datas, boolean isBack, int passengerCount) {
        super(context, R.layout.trip_item_detail_insure, datas);
        this.isBack = isBack;
        this.passengerCount = passengerCount;
    }

    @Override
    public void convert(ItemViewHolder holder, FlightOrderDetailEntity.OrderPriceDetailsBean.InsurancePricesBean entity) {
        TripItemDetailInsureBinding binding = DataBindingUtil.bind(holder.itemView);

        binding.insureName.setText(entity.getInsuranceName());
        if (isBack) {
            binding.insurePrice.setText("¥" + NumberUtil.trim0(entity.getInsuranceAmount() * 2 / passengerCount) + "*" + passengerCount + "人");
        } else {
            binding.insurePrice.setText("¥" + NumberUtil.trim0(entity.getInsuranceAmount() / passengerCount) + "*" + passengerCount + "人");
        }
    }

}
